package com.teng.mylibrary.widget

import android.view.View
import androidx.recyclerview.widget.LinearLayoutManager
import com.teng.mylibrary.ui.adapter.SingleChooseAdapter
import com.teng.mylibrary.base.BaseDialog
import com.teng.mylibrary.databinding.DialogChooseSingleBinding

/**
 * Description:  单选选择框
 * Author:       liuteng
 * CreateDate:   2021/9/15 15:07
 * UpdateRemark: 更新说明
 */
class SingleChooseDialog(val title: String, val list: ArrayList<String>) :
    BaseDialog<DialogChooseSingleBinding>(DialogChooseSingleBinding::inflate) {

    var mOnItemOkListener: ((positon: Int) -> Any?)? = null

    override fun initView(view: View?) {
        binding.tvTitle.text = title
        binding.recyclerView.layoutManager = LinearLayoutManager(context)
        val adapter = SingleChooseAdapter(list)
        binding.recyclerView.adapter = adapter
        adapter.setOnItemClickListener {
            mOnItemOkListener?.invoke(it)
            dismiss()
        }
    }

    override fun initData() {
        dialog!!.setCanceledOnTouchOutside(true)
    }

    /**
     * 确认
     */
    fun setOnItemOkListener(onItemOkListener: ((positon: Int) -> Any?)) {
        mOnItemOkListener = onItemOkListener
    }
}